//
//  GGResponseResult.h
//  cicada
//
//  Created by iOSer on 2016/12/14.
//  Copyright © 2016年 iOSer. All rights reserved.
//

#import <Foundation/Foundation.h>

#define GGResponseResultTypeSuccessMassage @"请求成功"
#define GGResponseResultTypeErrorMassage @"请求失败"
#define GGResponseResultTypeNetworkErrorMassage @"网络连接错误！"
#define GGResponseResultTypeRequestDataFormatErrorMassage @"请求数据有误"
#define GGResponseResultTypeResponseDataFormatErrorMassage @"服务器数据有误"
#define GGResponseResultTypeResponseDataZeroTrueMessage @"返回数据为空"
#define GGResponseResultTypeUnknownMassage @"未知错误"

/// 网络，返回的状态码
#define GGRequest_Status @"status"
/// 网络请求，返回的成功数据
#define GGRequest_DATA @"data"

#define CODE_INFO [NSString stringWithFormat:@"%s + %d",__PRETTY_FUNCTION__, __LINE__]

#define CODE_KEY @"code"
#define DATA_KEY @"data"

typedef NS_ENUM(NSInteger,GGResponseResultType) {
    /// 请求成功
    GGResponseResultTypeSuccess = 0,
    //请求失败
    GGResponseResultTypeError,
    /// 网络错误
    GGResponseResultTypeNetworkError,
    /// 请求数据格式有误
    GGResponseResultTypeRequestDataFormatError,
    /// 响应数据有误
    GGResponseResultTypeResponseDataFormatError = -1016,
    /// 请求成功，但是数据为空
    GGResponseResultTypeResponseDataZero,
    /// 未知错误
    GGResponseResultTypeUnknown
    
};

@interface GGResponseResult <ObjectType : NSObject *>: NSObject
//请求结果类型
@property(nonatomic,assign) GGResponseResultType resultStateType;
//网络请求信息
@property(nonatomic,strong) NSURLSessionDataTask *task;
//下载进度
@property(nonatomic,strong) NSProgress *downLoadProgress;
//上传进度
@property(nonatomic,strong) NSProgress *uploadProgress;
//字典
@property(nonatomic,copy) NSDictionary <NSString *,ObjectType> *dict;
//数组
@property(nonatomic,strong) NSMutableArray <ObjectType> *array;
//字符串
@property(nonatomic,copy) NSString *string;
//BOOL
@property(nonatomic,assign) BOOL isSuccess;
//返回体
@property(nonatomic,strong) ObjectType result;
//错误
@property(nonatomic,strong) NSError *error;
//显示信息(显示界面使用)
@property(nonatomic,copy) NSString *showMessage;
//日志信息(打印使用）
@property(nonatomic,copy) NSString *logMessage;
//返回的数据
@property(nonatomic,strong) id responseObject;
//缓存的数据
@property (nonatomic, strong) id responseCache;
//数据分页,单页最大数
@property (nonatomic, assign)NSInteger pageSize;
/*
 *  解析模型规则
 *  如果传入,则根据modelAnalysisKey取出返回体中的内容解析模型
 *  如果为空,则默认取出data
 */
@property (nonatomic, copy) NSString *modelAnalysisKey;
//解析类型
@property (nonatomic, assign) Class modelClass;
//解析后的模型
@property (nonatomic, strong) id model;



+(instancetype)resultWithTask:(NSURLSessionDataTask *)task error:(NSError *)error;
+(instancetype)resultWithTask:(NSURLSessionDataTask *)task responseObject:(id)responseObject;

@end
